package com.sdry.web.controller.workplace;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.jyy.Solid;
import com.sdry.model.jyy.SolidExample;
import com.sdry.model.jyy.SolidExample.Criteria;
import com.sdry.model.lz.DeviceModel;
import com.sdry.model.workplace.Centrifugal;
import com.sdry.model.workplace.CentrifugalExample;
import com.sdry.service.jyy.SolidServise;
import com.sdry.service.workplace.AssembleServise;
import com.sdry.service.workplace.CentrifugalServise;
import com.sdry.service.workplace.MousseBundleSampleServise;
import com.sdry.service.workplace.MousseSampleServise;
import com.sdry.service.workplace.OthersService;
import com.sdry.utils.ResponseUtil;

/**
 * @ClassName: OthersController
 * @Description: 生产工位相关
 * @author tdd
 * @date 2018年8月29日
 * @version V1.0
 */
@Controller
@RequestMapping("/revoke")
public class CentrifugalRevokeController {
	//离心机
	@Resource
    private CentrifugalServise centrifugalServise;
	//固化
	@Resource
    private SolidServise solidServise;
	@Resource
	private OthersService othersService;
	/**
	 * 离心机
	 * @param response
	 * @param centrifugal
	 * @throws Exception
	 */
    @RequestMapping("/centrifugal")
    public void centrifugal(HttpServletResponse response,Centrifugal centrifugal) throws Exception {
        //返回标识   0 失败   -1 已经在下一工位  -2已经删除   1成功
        int affact = 0;
        
        //1 根据台车条码查询数据库中是否存在此数据
  		SolidExample example = new SolidExample();
  		Criteria createCriteria = example.createCriteria();
  		createCriteria.andStubeEqualTo(centrifugal.getCtube());
  		List<Solid> list = solidServise.selectByExample(example );
  		if (list.size() > 0) {
  			affact = -1;
		}else{
			
			DeviceModel deviceModel = new DeviceModel();
			deviceModel.setDeviceNo(centrifugal.getCcode());
			List<DeviceModel> devices = othersService.deviceByMution(deviceModel);
			if(devices.size() > 0 ){
				deviceModel = devices.get(0);
				if(deviceModel.getRemark05() == "绑定"){
					//空闲
					int aff = centrifugalServise.deleteByPrimaryKeys(String.valueOf(centrifugal.getCid()));
					if(aff > 0){
						affact = 1;
					}
					CentrifugalExample centrifugalExample = new CentrifugalExample();
			        com.sdry.model.workplace.CentrifugalExample.Criteria createCriteria2 = centrifugalExample.createCriteria();
			        createCriteria2.andCcodeEqualTo(centrifugal.getCcode());
			        createCriteria2.andCremarkIsNull();
			        //是否报废   1是   0否
			        createCriteria2.andCremark1EqualTo("0");
			        List<Centrifugal> centrifugals = centrifugalServise.selectByExample(centrifugalExample);
		        	if(centrifugals.size() <= 0){
		        		deviceModel.setRemark05("空闲");
		        		//修改
		        		othersService.deviceUpdate(deviceModel);
		        	}
				}else{
					//不空闲
					affact = -1;
				}
			}else{
				int aff = centrifugalServise.deleteByPrimaryKeys(String.valueOf(centrifugal.getCid()));
				 if(aff > 0){
					 affact = 1;
				 }
			}
			 
		}
        ResponseUtil.write(response, affact);
    }

}
